<template>
    <div id="parts">
        <div class="operation"><el-button v-if="menuId==='4730'" @click="insertList" class="slot-btn-top" type="primary" size="small">发放任务</el-button></div>
        <el-table :data="dataList.slice((currentPage-1)*pagesize,currentPage*pagesize)" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="khxxName" label="客户信息" sortable min-width="250"></el-table-column>
            <el-table-column prop="productbatch" label="产品批号" sortable min-width="140"></el-table-column>
            <el-table-column prop="plandelivertime" label="计划发货时间" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
            <el-table-column prop="days" label="发货收款时间差" sortable min-width="140"></el-table-column>
            <el-table-column prop="tssj" label="任务启动时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="sfhrq" label="发货日期" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
            <el-table-column prop="kfryName" label="库房人员" sortable min-width="110"></el-table-column>
            <el-table-column prop="sfkrq" label="收款日期" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
            <el-table-column prop="cwryName" label="财务人员" sortable min-width="110"></el-table-column>
            <el-table-column prop="ksfprq" label="开发票日期" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
            <el-table-column prop="wcsj" label="任务完成时间" sortable min-width="170"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="90">
                <template slot-scope="scope"><el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button></template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize"
                       layout="total, sizes, prev, pager, next, jumper" :total="dataList.length"></el-pagination>

        <!-- 详情信息 -->
        <el-dialog :title="dialogTitle" width="90%" top="30px" :visible.sync="isDialog" :close-on-click-modal="false">
            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="任务信息" name="1" class="dialog1" :style="dialogHeightPane">

                    <!---->
                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务流水号"><el-input v-model="dialogList.tcode" :disabled="!dialogListDisabled.tcode"></el-input></el-form-item>
                        <el-form-item label="客户信息"><el-select v-model="dialogList.khxx" :disabled="!dialogListDisabled.khxx"><el-option v-for="item in customers" :key="item.code" :value="item.code" :label="item.name"></el-option></el-select></el-form-item>
                        <el-form-item label="产品批号"><el-input v-model="dialogList.productbatch" :disabled="!dialogListDisabled.productbatch"></el-input></el-form-item>
                        <el-form-item label="计划发货时间"><el-date-picker v-model="dialogList.plandelivertime" :disabled="!dialogListDisabled.plandelivertime" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="任务发布人"><el-input v-model="dialogList.bzryname" :disabled="!dialogListDisabled.bzryname"></el-input></el-form-item>
                        <el-form-item label="任务发布时间"><el-input v-model="dialogList.fbsj" :disabled="!dialogListDisabled.fbsj" ></el-input></el-form-item>
                        <el-form-item label="销售人员"><el-select v-model="dialogList.xsry" :disabled="!dialogListDisabled.xsry"><el-option v-for="item in purchases" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>启动信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务是否启动"><el-select v-model="dialogList.rwzt" :disabled="!dialogListDisabled.rwzt" @change="change2Time('rwzt','tssj')"><el-option :value="1" label="是"></el-option><el-option :value="0" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="任务启动时间"><el-input v-model="dialogList.tssj" :disabled="!dialogListDisabled.tssj"></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>发货信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="货物是否已发"><el-select v-model="dialogList.hwzt" :disabled="!dialogListDisabled.hwzt" @change="change2Time('hwzt','sfhsj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="发货日期"><el-date-picker v-model="dialogList.sfhrq" :disabled="!dialogListDisabled.sfhrq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="发货填写时间"><el-input v-model="dialogList.sfhsj" :disabled="!dialogListDisabled.sfhsj"></el-input></el-form-item>
                        <el-form-item label="库房人员"><el-select v-model="dialogList.kfry" :disabled="!dialogListDisabled.kfry"><el-option v-for="item in rooms" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>财务信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="货款是否已收"><el-select v-model="dialogList.hkzt" :disabled="!dialogListDisabled.hkzt"  @change="change2Time('hkzt','sfksj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="收款日期"><el-date-picker v-model="dialogList.sfkrq" :disabled="!dialogListDisabled.sfkrq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="收款填写时间"><el-input v-model="dialogList.sfksj" :disabled="!dialogListDisabled.sfksj"></el-input></el-form-item>
                        <el-form-item label="发票是否已开"><el-select v-model="dialogList.fpzt" :disabled="!dialogListDisabled.fpzt" @change="change2Time('fpzt','ksfpsj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="发票号"><el-input v-model="dialogList.invoicenums" :disabled="!dialogListDisabled.invoicenums"></el-input></el-form-item>
                        <el-form-item label="发票金额"><el-input v-model="dialogList.invoicesum" :disabled="!dialogListDisabled.invoicesum"></el-input></el-form-item>
                        <el-form-item label="开发票日期"><el-date-picker v-model="dialogList.ksfprq" :disabled="!dialogListDisabled.ksfprq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="开发票填写时间"><el-input v-model="dialogList.ksfpsj" :disabled="!dialogListDisabled.ksfpsj"></el-input></el-form-item>
                        <el-form-item label="财务人员"><el-select v-model="dialogList.cwry" :disabled="!dialogListDisabled.cwry"><el-option v-for="item in finance" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                        <el-form-item label="任务完成时间"><el-input v-model="dialogList.wcsj" :disabled="!dialogListDisabled.wcsj"></el-input></el-form-item>
                    </el-form>

                    <div style="text-align: right">
                        <el-button @click="submitList" type="primary">确 定</el-button>
                    </div>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="过程状态信息" name="2" :style="dialogHeightPane">
                    <el-button @click="insertProcessStateList" type="primary" size="small">新增</el-button>
                    <el-table :data="processStateData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="spname" label="商品名称" sortable min-width="200"></el-table-column>
                        <el-table-column prop="spxh" label="商品批号" sortable min-width="120"></el-table-column>
                        <el-table-column prop="spjhsl" label="商品计划数量" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhdj" label="商品计划单价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhzj" label="商品计划总价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="planarrivedtime" label="计划发货时间" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhsfsj" label="计划收款时间" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjsl" label="商品实际数量" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjdj" label="商品实际单价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjzj" label="商品实际总价" sortable min-width="130"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateProcessStateList(scope.row)" type="text" size="small">编辑
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="processStateData.length"></el-pagination>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="备注记录信息" name="3" :style="dialogHeightPane">
                    <el-button @click="insertNotesRecordList" type="primary" size="small" >新增</el-button>
                    <el-table :data="notesRecordData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 99%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="txrname" label="填写人" sortable min-width="100"></el-table-column>
                        <el-table-column prop="tdsj" label="填写时间" :formatter="formatTimestampToTime" sortable min-width="160"></el-table-column>
                        <el-table-column prop="tdnr" label="填写内容" sortable min-width="500"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateNotesRecordList(scope.row)" type="text" size="small">编辑</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="notesRecordData.length"></el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>

        <!-- 过程状态信息 -->
        <el-dialog :title="dialogProcessStateTitle" width="900px" center :visible.sync="isProcessStateDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogProcessStateList" label-position="right" label-width="180px">
                <el-form-item label="商品名称"><el-select v-model="dialogProcessStateList.spmc"><el-option v-for=" item in processStateSelectUserData" :key="item.code" :value="item.code" :label="item.name"></el-option></el-select></el-form-item>
                <el-form-item label="商品批号"><el-input v-model="dialogProcessStateList.spxh"></el-input></el-form-item>
                <el-form-item label="商品计划数量"><el-input v-model="dialogProcessStateList.spjhsl"></el-input></el-form-item>
                <el-form-item label="商品计划单价"><el-input v-model="dialogProcessStateList.spjhdj"></el-input></el-form-item>
                <el-form-item label="商品计划总价"><el-input v-model="dialogProcessStateList.spjhzj" disabled></el-input></el-form-item>
                <el-form-item label="计划到货时间"><el-date-picker v-model="dialogProcessStateList.planarrivedtime" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                <el-form-item label="计划付款时间"><el-date-picker v-model="dialogProcessStateList.spjhsfsj" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                <el-form-item label="商品实际数量"><el-input v-model="dialogProcessStateList.spsjsl" :disabled="dialogProcessStateTitle ==='添加'"></el-input></el-form-item>
                <el-form-item label="商品实际单价"><el-input v-model="dialogProcessStateList.spsjdj" :disabled="dialogProcessStateTitle ==='添加'"></el-input></el-form-item>
                <el-form-item label="商品实际总价"><el-input v-model="dialogProcessStateList.spsjzj" disabled></el-input></el-form-item>
                <el-form-item label="商品添加时间"><el-input v-model="dialogProcessStateList.sptjsj" disabled></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click="submitProcessStateList" type="primary">确 定</el-button>
            </div>
        </el-dialog>

        <!-- 备注记录信息 -->
        <el-dialog :title="dialogNotesRecordTitle" width="500px" center :visible.sync="isNotesRecordDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogNotesRecordList" label-position="right" label-width="180px">
                <el-form-item label="填写人"><el-input v-model="dialogNotesRecordList.txr" disabled></el-input></el-form-item>
                <el-form-item label="填写时间"><el-input v-model="dialogNotesRecordList.tdsj" disabled></el-input></el-form-item>
                <el-form-item label="填写内容"><el-input type="textarea" :rows="8" v-model="dialogNotesRecordList.tdnr" style="width: 200px;"></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;"><el-button @click="submitNotesRecordList" type="primary">确 定</el-button>
            </div>
        </el-dialog>


    </div>
</template>

<script>
    export default {
        name: "",
        data() {
            let token = sessionStorage.getItem("tokenId");
            let menuId = sessionStorage.getItem('menuId');
            let tableHeight = (menuId === '4730') ? (document.documentElement.clientHeight - 170) : (document.documentElement.clientHeight - 140);
            return {
                tokenId: token,
                menuId: menuId,
                currentPage: 1,
                pagesize: 100,
                activeName: '1',
                customers: [],
                purchases: [],
                rooms: [],
                finance: [],
                tableHeight: tableHeight,
                dataList: [],

                //基本信息
                isDialog: false,
                dialogTitle: '',
                dialogType: '',
                dialogHeightPane: {
                    height: (document.documentElement.clientHeight - 180) + 'px',
                    overflowY: 'auto'
                },
                dialogTableHeight: document.documentElement.clientHeight - 280,
                dialogList: {
                    bzry: '',
                    bzryname: '',
                    checkuptime: '',
                    cwry: '',
                    days: '',
                    fbsj: '',
                    fpzt: '',
                    fzry: '',
                    goodsname: '',
                    hkzt: '',
                    hwzt: '',
                    invoicenums: '',
                    invoicesum: '',
                    ischeckupgoods: '',
                    isproviderdeliver: '',
                    isproviderstockup: '',
                    kfry: '',
                    khxx: '',
                    khxxName: '',
                    ksfprq: '',
                    ksfpsj: '',
                    ordernums: '',
                    plandelivertime: '',
                    planpaytime: '',
                    productbatch: '',
                    productbatchs: '',
                    providerdelivertime: '',
                    rwlx: '',
                    rwwczt: '',
                    rwzt: '',
                    sfhrq: '',
                    sfhsj: '',
                    sfkrq: '',
                    sfksj: '',
                    startstockuptime: '',
                    sum: '',
                    tcode: '',
                    tid: '',
                    tssj: '',
                    wcsj: '',
                    xsry: '',
                },
                dialogListDisabled: {
                    bzry: true,
                    bzryname: true,
                    checkuptime: true,
                    cwry: true,
                    days: true,
                    fbsj: true,
                    fpzt: true,
                    fzry: true,
                    goodsname: true,
                    hkzt: true,
                    hwzt: true,
                    invoicenums: true,
                    invoicesum: true,
                    ischeckupgoods: true,
                    isproviderdeliver: true,
                    isproviderstockup: true,
                    kfry: true,
                    khxx: true,
                    khxxName: true,
                    ksfprq: true,
                    ksfpsj: true,
                    ordernums: true,
                    plandelivertime: true,
                    planpaytime: true,
                    productbatch: true,
                    productbatchs: true,
                    providerdelivertime: true,
                    rwlx: true,
                    rwwczt: true,
                    rwzt: true,
                    sfhrq: true,
                    sfhsj: true,
                    sfkrq: true,
                    sfksj: true,
                    startstockuptime: true,
                    sum: true,
                    tcode: true,
                    tid: true,
                    tssj: true,
                    wcsj: true,
                    xsry: true,
                },


                //过程状态信息
                isProcessStateDialog: false,
                dialogProcessStateTitle: '',
                dialogProcessStateList: {
                    commodityuse: '',
                    planarrivedtime: '',
                    rwlx: '',
                    sjtotal: '',
                    sjwhereweek: '',
                    spid: '',
                    spjhdj: '',
                    spjhsfsj: '',
                    spjhsl: '',
                    spjhzj: '',
                    spmc: '',
                    spname: '',
                    spsjdj: '',
                    spsjsl: '',
                    spsjzj: '',
                    sptjsj: '',
                    spxh: '',
                    tid: '',
                    total: '',
                    whereWeek: '',
                },
                processStateData: [],
                processStateSelectUserData: [],

                //备注记录
                isNotesRecordDialog: false,
                dialogNotesRecordTitle: '',
                dialogNotesRecordList: {
                    tdid:'',
                    txr:'',
                    tdsj:'',
                    tdnr:'',
                    tid:'',
                },
                notesRecordData: [],

            };
        },
        created() {
            this.getData();
            this.getCustomer();
            this.getPurchase();
            this.getRoom();
            this.getFinance();
        },
        methods: {
            getCustomer() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsTaskinfo/queryByKhxx?type=1&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.customers = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getPurchase() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsTaskinfo/queryByYY?roleid=132&tokenId='+_this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.purchases = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getRoom() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsTaskinfo/queryByYY?roleid=129&tokenId='+_this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.rooms = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getFinance() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsTaskinfo/queryByYY?roleid=130&tokenId='+_this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.finance = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getData() {
                let _this = this;
                let loading = this.$loading({
                    target: document.querySelector(".wrapper > .content-box"),
                    lock: true,
                    text: '正在努力加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.8)'
                });
                let id;
                if (_this.menuId === '4730') {
                    id = '?rwzt=0&rwwczt=0&rwlx=2&tokenId=' + _this.tokenId;
                } else if (_this.menuId === '4731') {
                    id = '?rwzt=1&rwwczt=0&rwlx=2&tokenId=' + _this.tokenId;
                } else if (_this.menuId === '4732') {
                    id = '?rwzt=1&rwwczt=1&rwlx=2&tokenId=' + _this.tokenId;
                }
                this.$http({
                    url: '/api/adscm/operation/cgxsTaskinfo/queryByRwlx' + id,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.dataList = res.data.content;
                        loading.close();
                    } else {
                        _this.$message.error(res.data.desc);
                        loading.close();
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    loading.close();
                })
            },
            insertList() {
                this.isDialog = true;
                this.dialogType = '1';
                this.dialogListDisabled = {
                    tcode: false,
                    productbatch: true,
                    xsry: true,
                    plandelivertime: true,
                    ordernums: false,
                    goodsname: true,
                    khxx:true,
                    khxxName:true,
                    bzry: false,
                    bzryname: false,
                    fbsj: false,
                    fzry: true,
                    rwzt: false,
                    tssj: false,
                    isproviderstockup: false,
                    ischeckupgoods: false,
                    checkuptime: false,
                    isproviderdeliver: false,
                    providerdelivertime: false,
                    hwzt: false,
                    sfhrq: false,
                    sfhsj: false,
                    kfry: false,
                    hkzt: false,
                    sfkrq: false,
                    sfksj: false,
                    fpzt: false,
                    invoicenums: false,
                    invoicesum: false,
                    ksfprq: false,
                    ksfpsj: false,
                    cwry: false,
                    wcsj: false,
                    days: false,
                    planpaytime: false,
                    productbatchs: false,
                    rwlx: false,
                    rwwczt: false,
                    startstockuptime: false,
                    sum: false,
                    tid: false,
                };
                this.dialogList = {
                    ordernums:'',
                    goodsname: '',
                    khxx: '',
                    khxxName: '',
                    bzry: '',
                    bzryname: '',
                    fbsj: this.this2Time(),
                    fzry:'',
                    rwzt: '',
                    tssj: '',
                    isproviderstockup: '',
                    ischeckupgoods: '',
                    checkuptime: '',
                    isproviderdeliver: '',
                    providerdelivertime: '',
                    hwzt: '',
                    sfhrq: '',
                    sfhsj: '',
                    kfry: '',
                    hkzt: '',
                    sfkrq: '',
                    sfksj: '',
                    fpzt: '',
                    invoicenums: '',
                    invoicesum: '',
                    ksfprq: '',
                    ksfpsj: '',
                    cwry: '',
                    wcsj: '',
                    days: '',

                    plandelivertime: '',
                    planpaytime: '',
                    productbatch: '',
                    productbatchs: '',
                    rwlx: '2',
                    rwwczt: '',
                    startstockuptime: '',
                    sum: '',
                    tcode: '',
                    tid: '',
                    xsry: '',
                };
            },
            updateList(row) {
                this.isDialog = true;
                this.dialogType = '2';
                this.activeName = '1';
                this.dialogListDisabled = {
                    tcode: false,
                    productbatch: this.menuId === '4730' ? true : false,
                    xsry: this.menuId === '4730' ? true : false,
                    plandelivertime: this.menuId === '4730' ? true : false,
                    ordernums: false,
                    goodsname: this.menuId === '4730' ? true : false,
                    khxx:this.menuId === '4730' ? true : false,
                    rwzt: this.menuId==='4732'?false:(this.menuId === '4730'||row.bzryname === localStorage.getItem('ms_username')? true:false),
                    khxxName:true,
                    bzry: false,
                    bzryname: false,
                    fbsj: false,
                    fzry: true,
                    tssj: false,
                    isproviderstockup: false,
                    ischeckupgoods: false,
                    checkuptime: false,
                    isproviderdeliver: false,
                    providerdelivertime: false,
                    hwzt: this.menuId === '4731' ? true : false,
                    sfhrq: this.menuId === '4731' ? true : false,
                    sfhsj: false,
                    kfry: this.menuId === '4731' ? true : false,
                    hkzt: this.menuId === '4731' ? true : false,
                    sfkrq: this.menuId === '4731' ? true : false,
                    sfksj: false,
                    fpzt: this.menuId === '4731' ? true : false,
                    invoicenums: this.menuId === '4731' ? true : false,
                    invoicesum: this.menuId === '4731' ? true : false,
                    ksfprq: this.menuId === '4731' ? true : false,
                    ksfpsj: false,
                    cwry: this.menuId === '4731' ? true : false,
                    wcsj: false,
                    days: false,
                    planpaytime: false,
                    productbatchs: false,
                    rwlx: false,
                    rwwczt: false,
                    startstockuptime: false,
                    sum: false,
                    tid: false,
                };
                this.dialogList = row;
            },
            submitList() {
                let _this = this;
                let url;
                if (_this.dialogType === '1') {
                    url = '/api/adscm/operation/cgxsTaskinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogType === '2') {
                    url = '/api/adscm/operation/cgxsTaskinfo/update?tokenId=' + _this.tokenId;
                }

                _this.dialogList.plandelivertime = _this.timestampToTime( _this.dialogList.plandelivertime  );
                _this.dialogList.sfhrq = _this.timestampToTime( _this.dialogList.sfhrq  );
                _this.dialogList.sfkrq = _this.timestampToTime( _this.dialogList.sfkrq  );
                _this.dialogList.ksfprq =_this.timestampToTime( _this.dialogList.ksfprq  );

                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogList));
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {
                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        _this.getData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },

            //过程状态信息
            getProcessStateSelectUserData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsCommodityinfo/querySalePro?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.processStateSelectUserData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getProcessStateData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsCommodityinfo/queryByTid?tid=' + _this.dialogList.tid + '&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log(res.data )

                    if (res.data.statusCode == 200) {
                        _this.processStateData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertProcessStateList() {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '添加';
                this.dialogProcessStateList = {
                    commodityuse: '',
                    planarrivedtime: '',
                    rwlx: '',
                    sjtotal: '',
                    sjwhereweek: '',
                    spid: '',
                    spjhdj: '',
                    spjhsfsj: '',
                    spjhsl: '',
                    spjhzj: '',
                    spmc: '',
                    spname: '',
                    spsjdj: '',
                    spsjsl: '',
                    spsjzj: '',
                    sptjsj: this.this2Time(),
                    spxh: '',
                    tid: this.dialogList.tid,
                    total: '',
                    whereWeek: '',
                };
            },
            updateProcessStateList(row) {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '编辑';
                this.dialogProcessStateList = row;
                this.dialogProcessStateList.commodityuse = parseInt(this.dialogProcessStateList.commodityuse);
            },
            submitProcessStateList() {
                let _this = this;
                let url;
                if (_this.dialogProcessStateTitle === '添加') {
                    url = '/api/adscm/operation/cgxsCommodityinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogProcessStateTitle === '编辑') {
                    url = '/api/adscm/operation/cgxsCommodityinfo/update?tokenId=' + _this.tokenId;
                }
                this.dialogProcessStateList.planarrivedtime = this.timestampToTime(this.dialogProcessStateList.planarrivedtime);
                this.dialogProcessStateList.spjhsfsj = this.timestampToTime(this.dialogProcessStateList.spjhsfsj);

                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogProcessStateList));
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isProcessStateDialog = false;
                        _this.getProcessStateData();

                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },

            //备注记录信息
            getNotesRecordData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/baseTaskdetailinfo/queryByTid?tid=' +_this.dialogList.tid+ '&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.notesRecordData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertNotesRecordList() {
                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '添加';
                this.dialogNotesRecordList = {
                    tdid:'',
                    txr:'',
                    tdsj:'',
                    tdnr:'',
                    tid:this.dialogList.tid,
                };
            },
            updateNotesRecordList(row) {

                console.log( row )

                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '编辑';
                this.dialogNotesRecordList = row;
            },
            submitNotesRecordList() {
                let _this = this;
                let url;
                if (_this.dialogNotesRecordTitle === '添加') {
                    url = '/api/adscm/operation/baseTaskdetailinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogNotesRecordTitle === '编辑') {
                    url = '/api/adscm/operation/baseTaskdetailinfo/update?tokenId=' + _this.tokenId;
                }
                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogNotesRecordList));

                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.isNotesRecordDialog = false;
                        _this.getNotesRecordData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },


            change2Time( isOk ,eTime){
                if ( this.dialogList[isOk] == 1) {
                    let date = new Date();
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    this.dialogList[eTime] =  Y + M + D + h + m + s;
                }
            },
            handleClick(tab, event) {
                if (tab.name === '2') {
                    this.getProcessStateData();
                    this.getProcessStateSelectUserData();
                } else if (tab.name === '3') {
                    this.getNotesRecordData();
                }
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
            },
            formatTimestampToTime:function(row, column, cellValue, index) {
        return cellValue ? this.timestampToTime(cellValue) : '';
    },
            formatDityUse:function(row, column, cellValue, index) {
                return cellValue == '0' ? '其他' : (cellValue == '1' ? '耗材生产' : (cellValue == '2' ? '机器生产' : ''));
            },
            formatTimestampToDate:function(row, column, cellValue, index) {
                return cellValue ? this.timestampToTime(cellValue).substr(0,10) : '';
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    return timestamp ? Y + M + D + h + m + s : '';
                } else {
                    return '';
                }
            },
            this2Time() {
                    let date = new Date();
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    return  Y + M + D + h + m + s ;
            },
        }
    }
</script>

<style scoped>

    #parts .el-table--small {
        font-size: 13px;
    }

    #parts .el-table .cell,
    #parts .el-table th div {
        padding-left: 0;
        padding-right: 0;
    }

    #parts .el-tab-pane.dialog1 .el-form {
        margin-bottom: 30px;
    }

</style>
